#include "gtest/gtest.h"

#include <memory>
#include "MemoryStream.h"

using namespace streamdb;


TEST(MemoryStreamTest, use){
    std::shared_ptr<SequenceStream<OrderedMessage>> ss(new MemoryStream);

    ASSERT_TRUE(ss->append(OrderedMessage::Null).isOk());
    ASSERT_TRUE(ss->append(OrderedMessage::Null).isOk());
    ASSERT_TRUE(ss->append(OrderedMessage::Null).isOk());
    ASSERT_TRUE(ss->append(OrderedMessage::Null).isOk());
    ASSERT_TRUE(ss->append({1, "10000"}).isOk());
    ASSERT_TRUE(ss->append({2, "10000"}).isOk());
    ASSERT_TRUE(ss->append({3, "10000"}).isOk());
    ASSERT_TRUE(ss->getSize() == 3);

    int offset = 1;
    {
        auto iter = ss->advance(offset);
        if(iter != nullptr){
            for(int i =0 ; i < 10 && iter->hasNext(); ++i){
                auto & v = iter->next();
                std::cout << "max 10:" << v.toString() << std::endl;
            }
        }
    }
    {
        auto iter = ss->advance(offset);
        if(iter != nullptr){
            while(iter->hasNext()){
                auto & v = iter->next();
                v.id = 1000;
                std::cout << "iterator from offset(" << offset << ")/" << ss->getSize() << ":" << v.toString() << std::endl;
            }
        }
    }
}
